﻿using System;
using System.Collections.Generic;
using QuickGraph;

namespace InteractiveFiction.Model
{
    public class Character : Noun
    {
        public Character(string name, StoryNode location) : base(name)
        {
            Inventory = new List<StoryItem>();
            History = new List<StoryEdge>();
            Name = name;
            Location = location;
        }

        public List<StoryItem> Inventory { get; private set; }
        public List<StoryEdge> History { get; private set; }
        public string Name { get; private set; }
        public StoryNode Location { get; private set; }

        public void MoveInDirection(Direction direction, ArrayBidirectionalGraph<StoryNode, StoryEdge> graph)
        {
            foreach (StoryEdge edge in graph.OutEdges(Location))
            {
                if (edge.DirectionToTarget == direction)
                    Move(edge);
            }
        }

        public void Move(StoryEdge edge)
        {
            if (edge.AllowedToTransverse(this))
                Location = edge.Target;
            else if (edge.Redirect != null)
                Location = edge.Redirect;
            //Display the denial text
        }

        public void PickUpItem(StoryItem item)
        {
            if (Location.Items.Contains(item))
            {
                Inventory.Add(item);
                Location.Items.Remove(item);
            }
        }

        public void Dropitem(StoryItem item)
        {
            if (Inventory.Contains(item))
            {
                Location.Items.Add(item);
                Inventory.Remove(item);
            }
        }

        
    }
}
